package com.szx.usercenter.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.szx.usercenter.domain.UserFileNumber;
import com.szx.usercenter.service.UserFileNumberService;
import com.szx.usercenter.util.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author songzx
 * @create 2024-06-05 9:11
 */
@Api(tags = "用户容量管理")
@RestController
@RequestMapping("/userFileNumber")
public class UserFileNumberController {
    @Resource
    UserFileNumberService fileNumberService;

    @ApiOperation("获取用户容量")
    @GetMapping("getNumber")
    public Response getNumber(HttpServletRequest request) {
        UserFileNumber userFileNumber = fileNumberService.getUserFileNumber(request);
        return Response.rspData(userFileNumber);
    }

    @ApiOperation("获取用户容量")
    @GetMapping("getNumber/{userId}")
    public Response getNumberByUserId(@PathVariable String userId) {
        UserFileNumber one = fileNumberService.getOne(
                new LambdaQueryWrapper<UserFileNumber>().eq(UserFileNumber::getUserId, userId));
        return Response.rspData(one);
    }

    @ApiOperation("更新用户容量")
    @PostMapping("updateUserNumber")
    public Response updateUserNumber(Long userId, Long size) {
        boolean b = fileNumberService.updateUserNumber(userId, size);
        return b ? Response.success() : Response.error();
    }
}
